****************************************************************************************************
* Reproduction Code for:														********************
* Rising Inequality and Public Support for Redistribution						********************
* Sven Hillen & Nils Steiner													********************
* European Journal of Political Research										********************
****************************************************************************************************

/*
Instructions:
This do-file reproduces all findings reported in the article named above.
To reproduce the findings, do the following
1. Install ados and graph schemes used (if necessary), as follows
	ssc install fre
	ssc install estout
	ssc install coefplot
	ssc install egenmore
	net install mibeta.pkg
	ssc install schemepack, replace all
	
2. Download datasets used:
	a) ISSP Social Inequality data from all five rounds published thus far: https://www.gesis.org/en/issp/data-and-documentation/social-inequality
	b) Data with ISSP survey years from our reproduction archive: ISSP_surveyyears.dta
	c) Combined Macro Data (SWIID, WID, V-DEM, World Bank): MacroData.dta
	
3. Put the datasets and this reproduction do-file into one folder (and set this as the working directory)

4. Run the code below on the combined dataset
*/



**# Bookmark #1
****************************************************************************************************
**************************************** General Settings ******************************************
****************************************************************************************************
	set more off, perm
	version 18.0
	set scheme white_tableau
	graph set window fontface "Times New Roman"


	
**# Bookmark #2
****************************************************************************************************
******************************** Open, Recode and Combine ISSP data ********************************
****************************************************************************************************
clear

******************************************************************************
********** Open ISSP Social Inequality data for round 1 (ISSP 1987) **********
******************************************************************************
use "ZA1680.dta" 

* Year
gen year=1987

***** Country identifiers 
fre v3

* Enter two-letter country codes
	generate country="AU" if v3==1	
	replace country="DE" if v3==2	
	replace country="GB" if v3==3	
	replace country="US" if v3==4	
	replace country="AT" if v3==5
	replace country="HU" if v3==6	
	replace country="NL" if v3==7
	replace country="IT" if v3==8
	replace country="CH" if v3==11
	replace country="PL" if v3==12

	
***** Recoding of variables	

	* Redistribution support (Q: "It is the responsibility of the government to reduce the differences in income between people with high incomes and those with low incomes")
	recode v49 (1=4) (2=3) (3=2) (4=1) (5=0), gen(redistribution)
	
	* Income differences are too large (Q: "Differences in income in [COUNTRY] are too large")
	recode v48 (5=0) (4=1) (3=2) (2=3) (1=4), gen(incdiffstoolarge)
	
	* Taxes for high vs. low incomes (Q: "Do you think that people with high incomes should pay a larger share of their income in taxes than those with low incomes, the same share, or a smaller share")
	recode v58 (5=0 "much smaller share") (4=1 "smaller share")  (3=2 "the same share")  (2=3 "larger share")  (1=4 "much larger share"), gen(tax_richvspoor)
	
	* Weight
	clonevar weight=v107
	
	* Sex
	clonevar male=v83
	recode male (2=0)
	
	* Age group
	recode v82 (1 2 16/24=1) (3 25/34=2) (4 35/44=3) (5 45/54=4) (6 55/64=5) (7 65/74=6) (8 75/91=7) (99=.), gen(age_intervals)

	label define age_intervals ///
		1	"under 25" ///
		2 	"25-34 years" ///
		3 	"35-44 years" ///
		4 	"45-54 years" ///
		5	"55-64 years" ///
		6	"65-74 years" ///
		7	"75 and more"
	label values age_intervals age_intervals
	
	* Education 
	gen education = .
	replace education = 1 if v88==1 | v88==2
	
	// AU
	replace education = 1 if v88==3 & country=="AU" | v88==4 & country=="AU"
	replace education = 2 if v88==5 & country=="AU" | v88==6 & country=="AU"
	replace education = 3 if v88==7 & country=="AU" | v88==8 & country=="AU" | v88==9 & country=="AU"
	
	// DE
	replace education = 1 if v88==3 & country=="DE" | v88==4 & country=="DE"
	replace education = 2 if v88==5 & country=="DE" | v88==6 & country=="DE" | v88==7 & country=="DE"
	replace education = 3 if v88==8 & country=="DE" | v88==9 & country=="DE"
	
	// GB
	replace education = 1 if v88==3 & country=="GB"
	replace education = 2 if v88==4 & country=="GB" | v88==5 & country=="GB" | v88==6 & country=="GB"
	replace education = 3 if v88==7 & country=="GB" | v88==8 & country=="GB"
	
	// US
	replace education = 2 if v88==3 & country=="US"
	replace education = 3 if v88==4 & country=="US" | v88==5 & country=="US" | v88==6 & country=="US"
	
	// AT
	replace education = 1 if v88==3 & country=="AT" | v88==4 & country=="AT" | v88==6 & country=="AT"
	replace education = 2 if v88==5 & country=="AT" | v88==7 & country=="AT"
	replace education = 3 if v88==8 & country=="AT"
	
	// HU
	replace education = 1 if v88==3 & country=="HU" | v88==4 & country=="HU"
	replace education = 2 if v88==5 & country=="HU"
	replace education = 3 if v88==7 & country=="HU"
	
	// NL
	replace education = 1 if v88==3 & country=="NL" | v88==4 & country=="NL" | v88==5 & country=="NL"
	replace education = 2 if v88==6 & country=="NL" | v88==7 & country=="NL"
	replace education = 3 if v88==8 & country=="NL"
	
	// IT
	replace education = 1 if v88==3 & country=="IT" | v88==4 & country=="IT" | v88==5 & country=="IT" | v88==6 & country=="IT"
	replace education = 2 if v88==7 & country=="IT" | v88==8 & country=="IT"
	replace education = 3 if v88==9 & country=="IT"
	
	// CH
	replace education = 1 if v88==4 & country=="CH"
	replace education = 2 if v88==3 & country=="CH" | v88==5 & country=="CH" | v88==6 & country=="CH" | v88==8 & country=="CH"
	replace education = 3 if v88==7 & country=="CH" | v88==9 & country=="CH"
	
	// PL
	replace education = 1 if v88==3 & country=="PL" | v88==4 & country=="PL"
	replace education = 2 if v88==5 & country=="PL" | v88==6 & country=="PL" | v88==8 & country=="PL"
	replace education = 3 if v88==7 & country=="PL" | v88==9 & country=="PL"
		
	label define degree ///
		1	"Primary or less" ///
		2	"Secondary" ///
		3	"Tertiary"
	label values education degree
	
	* Income
		* 1. generate exact numerical household/family income
			* A. directly use numerical variable (to the extent available)
			clonevar income=v92
				// only available for: AU, DE, HU, NL
				// declare missing values (where necessary)
				replace income=. if country=="DE" & (income==99997 | income==99998 | income==99999)
	
			* B. code numerical value from categorical income variable 
				// following Weisstanner: 
				// "Following Donnelly and Pop-Eleches (2018, p. 358–359), I assign midpoints of the income bands shown to respondents and apply a correction for imputing the midpoint of the top category.
				// The correction uses the width of the second-highest category plus the lower bound of the highest category. 
				// The example given by Donnelly and Pop-Eleches (2018, p. 359) has a second-highest category that ranges from $50,000 to $60,000 and a top category of $60,000 and above. 
				// Hence, they impute the income of the second-highest category as $55,000 and the income for the highest category as $70,000."
			// AT
			recode v93 (1=2000) (2=5000) (3=7000) (4=9000) (5=11000) (6=13000) (7=15000) (8=17000) (9=19000) (10=21000) (11=23000) (12=25000) (13=27000) (14=29000) (15=31000) (16=33000) (17=35000) (18=37000) (19=39000) (20=42000) if country=="AT", gen(income_AT)
			replace income=income_AT if country=="AT"

			// CH
			recode v93 (1=250) (2=750) (3=1250) (4=1750) (5=2250) (6=2750) (7=3500) (8=4500) (9=5500) (10=8000) (11=15000) (12=30000) if country=="CH", gen(income_CH)
			replace income=income_CH if country=="CH"

			// GB
			recode v93 (1=1000) (2=2500) (3=3500) (4=4500) (5=5500) (6=6500) (7=7500) (8=9000) (9=11000) (10=13500) (11=16500) (12=19000) (13=22000) if country=="GB", gen(income_GB)
			replace income=income_GB if country=="GB"
						
			// US
			recode v93 (1=500) (2=2000) (3=3500) (4=4500) (5=5500) (6=6500) (7=7500) (8=9000) (9=11250) (10=13750) (11=16250) (12=18750) (13=21250) (14=23750) (15=27500) (16=32500) (17=37500) (18=45000) (19=55000) (20=70000) if country=="US", gen(income_US)
			replace income=income_US if country=="US"
		
		* 2. divide household income by square root of household size
				// following Weisstanner: ""I adjust incomes for household size (dividing by the square root of number of household members)"
				// no distinction is made between adults and children (not available in all ISSP waves)
			gen income_equi=income/(sqrt(v86))
			
		* 3. use personal income as second best solution where it is not possible to calculate equivalized household income 
			// IT --> household size missing (v86)
			gen income_equi_IT=v94*1000 if country=="IT"
			replace income_equi=income_equi_IT if country=="IT"
		
			// PL --> household/family income missing
			clonevar income_equi_PL=v94 if country=="PL"		
			replace income_equi=income_equi_PL if country=="PL"
		
		* 4. code into quintiles
			egen income_equi_quint=xtile(income_equi), n(5) by(country)
			
		* 5. check whether this has worked
			bysort country: fre income_equi_quint

		* 6. code into deciles
			egen income_equi_dec=xtile(income_equi), n(10) by(country)
			
		* 7. check whether this has worked
			bysort country: fre income_equi_dec

			
* keep variables
keep year country redistribution incdiffstoolarge redistribution income_equi* weight male age_intervals education tax_richvspoor

save "ISSP1987.dta", replace


******************************************************************************
********** Open ISSP Social Inequality data for round 2 (ISSP 1992) **********
******************************************************************************
use "ZA2310.dta" 

* Year
gen year=1992
	
***** Country identifiers 
fre v3

* Enter two-letter country codes
	generate country="AU" if v3==1
	replace country="DE" if v3==2
	replace country="DE" if v3==3
	replace country="GB" if v3==4
	replace country="US" if v3==5
	replace country="AT" if v3==6
	replace country="HU" if v3==7
	replace country="IT" if v3==8
	replace country="NO" if v3==9
	replace country="SE" if v3==10
	replace country="CZ" if v3==11 & cz126<=8
	replace country="SK" if v3==11 & cz126>=9
	replace country="SI" if v3==12
	replace country="PL" if v3==13
	replace country="BG" if v3==14
	replace country="RU" if v3==15
	replace country="NZ" if v3==16
	replace country="CA" if v3==17
	replace country="PH" if v3==18


***** Recoding of variables
	
	* Redistribution support (Q: "It is the responsibility of the government to reduce the differences in income between people with high incomes and those with low incomes")
	recode v57 (1=4) (2=3) (3=2) (4=1) (5=0), gen(redistribution)
	
	* Income differences are too large (Q: "Differences in income in [COUNTRY] are too large")
	recode v56 (5=0) (4=1) (3=2) (2=3) (1=4), gen(incdiffstoolarge)

	* Taxes for high vs. low incomes (Q: "Do you think that people with high incomes should pay a larger share of their income in taxes than those with low incomes, the same share, or a smaller share")
	recode v66 (5=0 "much smaller share") (4=1 "smaller share")  (3=2 "the same share")  (2=3 "larger share")  (1=4 "much larger share"), gen(tax_richvspoor)

	* Weight
	clonevar weight=v176

	* Sex
	clonevar male=v99
	recode male (2=0)

	* Age
	recode v100 (16/24=1) (25/34=2) (35/44=3) (45/54=4) (55/64=5) (65/74=6) (75/92=7) (99=.), gen(age_intervals)

	label define age_intervals ///
		1	"under 25" ///
		2 	"25-34 years" ///
		3 	"35-44 years" ///
		4 	"45-54 years" ///
		5	"55-64 years" ///
		6	"65-74 years" ///
		7	"75 and more"
	label values age_intervals age_intervals

	replace age_intervals=1 if i100==1
	replace age_intervals=2 if i100==2
	replace age_intervals=3 if i100==3
	replace age_intervals=4 if i100==4
	replace age_intervals=5 if i100==5
	replace age_intervals=6 if i100==6

	* Education 
	gen education = .

	// AU, CS, PL, BG
	replace education = 1 if v103==1 | v103==2 | v103==3 | v103==4 
	replace education = 2 if v103==5 | v103==6 | v103==8
	replace education = 3 if v103==7 | v103==9

	// DE
	replace education = 1 if d103==1 | d103==2 | d103==3 | d103==4
	replace education = 2 if d103==5 | d103==6

	// GB
	replace education = 1 if gb103==1
	replace education = 2 if gb103==2 | gb103==3 | gb103==4
	replace education = 3 if gb103==5 | gb103==6

	// US 
	replace education = 1 if usa103==1 | usa103==3
	replace education = 2 if usa103==4
	replace education = 3 if usa103==5 | usa103==6 | usa103==7

	// AT
	replace education = 1 if a103==3 | a103==4 | a103==5
	replace education = 2 if a103==6
	replace education = 3 if a103==7 | a103==8

	// HU
	replace education = 1 if h103==1 | h103==2 | h103==3 | h103==4 | h103==5
	replace education = 2 if h103==6
	replace education = 3 if h103==7 | h103==8

	// IT
	replace education = 1 if i103==1 | i103==2 | i103==3 | i103==4 | i103==5 | i103==6
	replace education = 2 if i103==7 | i103==8
	replace education = 3 if i103==9

	// NO
	replace education = 1 if n103==3 | n103==5
	replace education = 2 if n103==6 | n103==7
	replace education = 3 if n103==8 | n103==9

	// SE
	replace education = 1 if s103==1
	replace education = 2 if s103==2 | s103==3
	replace education = 3 if s103==4

	// SL
	replace education = 1 if slo103==1 | slo103==2 | slo103==3 | slo103==4 | slo103==5
	replace education = 2 if slo103==6 | slo103==7
	replace education = 3 if slo103==8 | slo103==9

	// RU
	replace education = 1 if rus103==1 | rus103==2 | rus103==3 
	replace education = 2 if rus103==4 | rus103==5 | rus103==6 | rus103==7 | rus103==8
	replace education = 3 if rus103==9

	// NZ
	replace education = 1 if nz103==1 | nz103==2 | nz103==3
	replace education = 2 if nz103==4 | nz103==5 | nz103==6
	replace education = 3 if nz103==7

	// CA
	replace education = 1 if cdn103==1 | cdn103==2 | cdn103==3
	replace education = 2 if cdn103==4 | cdn103==5
	replace education = 3 if cdn103==6 | cdn103==7 | cdn103==8

	// PH
	replace education = 1 if rp103==1 | rp103==2 | rp103==3 | rp103==4
	replace education = 2 if rp103==5 | rp103==6
	replace education = 3 if rp103==7 | rp103==8

	label define degree ///
		1	"Primary or less" ///
		2	"Secondary" ///
		3	"Tertiary"
	label values education degree

	
	* Income
		* 1. generate exact numerical household/family income
			* A. directly use numerical variable (to the extent available)
			gen income = .
			replace h115=h115*1000
			replace rus115=rus115*1000
	foreach ct in aus d usa h cz slo pl rus {
		replace income = `ct'115 if `ct'115 !=.
	}
				// only available for: AU, DE, US, HU, CZ, SK, SI, PL, RU, 
				// declare missing values (where necessary)
					
			* B. code numerical value from categorical income variable 
				
			// GB
			recode gb116 (3=1500) (5=5000) (7=7000) (8=9000) (9=11000) (10=13500) (11=16500) (12=19000) (13=21500) (14=24500) (15=27500) (16=30500) (17=33500) (18=38000), gen(income_GB)
			replace income=income_GB if country=="GB"
			
			// AT
			recode a116 (1=2000) (2=5000) (3=7000) (4=9000) (5=11000) (6=13000) (7=15000) (8=17000) (9=19000) (10=21000) (11=23000) (12=25000) (13=27000) (14=29000) (15=31000) (16=33000) (17=35000) (18=37000) (19=39000) (20=42000), gen(income_AT)
			replace income=income_AT if country=="AT"
			
			// IT
			recode i116 (1=150000) (2=450000) (3=750000) (4=1050000) (5=1350000) (6=1650000) (7=1950000) (8=2250000) (9=255000) (10=2850000) (11=3150000) (12=3450000) (13=3750000) (14=4050000) (15=4350000) (16=4650000) (17=4950000) (18=5400000), gen(income_IT)
			replace income=income_IT if country=="IT"
		
			// NO
			recode n116 (1=25000) (2=745000) (3=124500) (4=174500) (5=224500) (6=274500) (7=349500) (8=449500) (9=599000) (10=13750), gen(income_NO)
			replace income=income_NO if country=="NO"

			// NZ
			recode nz116 (1=5000) (2=12500) (3=17500) (4=22500) (5=27500) (6=35000) (7=45000) (8=60000) (9=90000), gen(income_NZ)
			replace income=income_NZ if country=="NZ"

			// CA
			recode cdn116 (1=7500) (2=20000) (3=30000) (4=40000) (5=50000) (6=60000) (7=70000) (8=85000), gen(income_CA)
			replace income=income_CA if country=="CA"	
			
		* 2. divide household income by square root of household size
			gen income_equi=income/(sqrt(v119))
			
		* 3. use personal income as second best solution where it is not possible to calculate equivalized household income 
			
			// SE --> household/family income missing
			clonevar income_equi_SE=s117		
			replace income_equi=income_equi_SE if country=="SE"
			
			// BG --> household/family income missing
			clonevar income_equi_PL=bg117 		
			replace income_equi=income_equi_PL if country=="BG"
			
			// PH --> household/family income missing
			clonevar income_equi_PH=rp117	
			replace income_equi=income_equi_PH if country=="PH"
		
		* 4. code into quintiles
			egen income_equi_quint=xtile(income_equi), n(5) by(country)

		* 5. check whether this has worked
			bysort country: fre income_equi_quint

		* 6. code into deciles
			egen income_equi_dec=xtile(income_equi), n(10) by(country)
			
		* 7. check whether this has worked
			bysort country: fre income_equi_dec
		
		
* keep variables
keep year country redistribution incdiffstoolarge income_equi* weight male age_intervals education  tax_richvspoor

save "ISSP1992.dta", replace


******************************************************************************
********** Open ISSP Social Inequality data for round 3 (ISSP 1999) **********
******************************************************************************
use "ZA3430.dta" 

* Year
gen year=1999

***** Country identifiers 
fre v3

	* Enter two-letter country codes
	generate country="AU" if v3==1
	replace country="DE" if v3==2
	replace country="DE" if v3==3
	replace country="GB" if v3==4
	replace country="GB" if v3==5
	replace country="US" if v3==6
	replace country="AT" if v3==7
	replace country="HU" if v3==8

	replace country="NO" if v3==12
	replace country="SE" if v3==13
	replace country="CZ" if v3==14
	replace country="SI" if v3==15
	replace country="PL" if v3==16
	replace country="BG" if v3==17
	replace country="RU" if v3==18
	replace country="NZ" if v3==19
	replace country="CA" if v3==20
	replace country="PH" if v3==21
	replace country="IL" if v3==22

	replace country="JP" if v3==24
	replace country="ES" if v3==25
	replace country="LV" if v3==26
	replace country="FR" if v3==27
	replace country="CY" if v3==28
	replace country="PT" if v3==29
	replace country="CL" if v3==30
	replace country="SK" if v3==33


***** Recoding of variables
	
	* Redistribution support (Q: "It is the responsibility of the government to reduce the differences in income between people with high incomes and those with low incomes")
	recode v35 (1=4) (2=3) (3=2) (4=1) (5=0) (8 9=.), gen(redistribution)

	* Income differences are too large (Q: "Differences in income in [COUNTRY] are too large")
	recode v34 (5=0) (4=1) (3=2) (2=3) (1=4) (8 9=.), gen(incdiffstoolarge)

	* Taxes for high vs. low incomes (Q: "Do you think that people with high incomes should pay a larger share of their income in taxes than those with low incomes, the same share, or a smaller share")
	recode v36 (5=0 "much smaller share") (4=1 "smaller share")  (3=2 "the same share")  (2=3 "larger share")  (1=4 "much larger share") (8 9=. ), gen(tax_richvspoor)

	* Sex
	recode sex (2=0), gen(male)

	* Age
	recode age (16/24=1) (25/34=2) (35/44=3) (45/54=4) (55/64=5) (65/74=6) (75/96=7) (98=.), gen(age_intervals)

	label define age_intervals ///
		1	"under 25" ///
		2 	"25-34 years" ///
		3 	"35-44 years" ///
		4 	"45-54 years" ///
		5	"55-64 years" ///
		6	"65-74 years" ///
		7	"75 and more"
	label values age_intervals age_intervals

	* Education
	recode degree (1 2 3 4=1) (5 6=2) (7=3), gen(education)

	label define degree ///
		1	"Primary or less" ///
		2	"Secondary" ///
		3	"Tertiary"
	label values education degree


	* Income
	* 1. generate exact numerical household/family income
		* A. directly use numerical variable (to the extent available)
		
	/// Income variable already exists 
			// only available for: 
			// declare missing values (where necessary)
			replace income = . if income ==999996
			replace income = . if income ==999997
			replace income = . if income ==999998
			replace income = . if income ==999999
			replace income = . if income ==0
			
		* B. code numerical value from categorical income variable 
		
	* 2. divide household income by square root of household size
		replace hompop =. if hompop ==0 
		replace hompop =. if hompop ==99
		gen income_equi=income/(sqrt(hompop)) if hompop
		
	* 3. use personal income as second best solution where it is not possible to calculate equivalized household income 
		* Israel has missing values in family income variable
		replace rincome=. if country=="IL" & rincome==999999
		replace income_equi=rincome if country=="IL" 
		
	* 4. code into quintiles
		egen income_equi_quint=xtile(income_equi), n(5) by(country)

	* 5. check whether this has worked
		bysort country: fre income_equi_quint

	* 6. code into deciles
		egen income_equi_dec=xtile(income_equi), n(10) by(country)
		
	* 7. check whether this has worked
		bysort country: fre income_equi_dec
		

* keep variables
keep year country redistribution incdiffstoolarge income_equi* weight male age_intervals education tax_richvspoor

save "ISSP1999.dta", replace



******************************************************************************
********** Open ISSP Social Inequality data for round 4 (ISSP 2009) **********
******************************************************************************
use "ZA5400_v4-0-0.dta" 

* Year
gen year=2009

***** Country identifiers 
fre V5

	* Enter two-letter country codes
	generate country="AR" if V5==32
	replace country="AU" if V5==36
	replace country="AT" if V5==40
	replace country="BE" if V5==56
	replace country="BG" if V5==100
	replace country="CL" if V5==152
	replace country="CN" if V5==156
	replace country="TW" if V5==158
	replace country="HR" if V5==191
	replace country="CY" if V5==196
	replace country="CZ" if V5==203
	replace country="DK" if V5==208
	replace country="EE" if V5==233
	replace country="FI" if V5==246
	replace country="FR" if V5==250
	replace country="DE" if V5==276
	replace country="HU" if V5==348
	replace country="IS" if V5==352
	replace country="IL" if V5==376
	replace country="IT" if V5==380
	replace country="JP" if V5==392
	replace country="KR" if V5==410
	replace country="LV" if V5==428
	replace country="LT" if V5==440
	replace country="NZ" if V5==554
	replace country="NO" if V5==578
	replace country="PH" if V5==608
	replace country="PL" if V5==616
	replace country="PT" if V5==620
	replace country="RU" if V5==643
	replace country="SK" if V5==703
	replace country="SI" if V5==705
	replace country="ZA" if V5==710
	replace country="ES" if V5==724
	replace country="SE" if V5==752
	replace country="CH" if V5==756
	replace country="TR" if V5==792
	replace country="UA" if V5==804
	replace country="GB" if V5==826
	replace country="US" if V5==840
	replace country="VE" if V5==862

	
***** Recoding of variables	
	
	* Redistribution support (Q: "It is the responsibility of the government to reduce the differences in income between people with high incomes and those with low incomes")
	recode V33 (1=4) (2=3) (3=2) (4=1) (5=0) (8 9=.), gen(redistribution)
	
	* Income differences are too large (Q: "Differences in income in [COUNTRY] are too large")
	recode V32 (5=0) (4=1) (3=2) (2=3) (1=4) (8 9=.), gen(incdiffstoolarge)
	
	* Taxes for high vs. low incomes (Q: "Do you think that people with high incomes should pay a larger share of their income in taxes than those with low incomes, the same share, or a smaller share")
	recode V36 (5=0 "much smaller share") (4=1 "smaller share")  (3=2 "the same share")  (2=3 "larger share")  (1=4 "much larger share") (8 9=. ), gen(tax_richvspoor)
	
	* Weight
	clonevar weight=WEIGHT

	* Sex
	recode SEX (2=0) (9=.), gen(male)

	* Age
	recode AGE (15/24=1) (25/34=2) (35/44=3) (45/54=4) (55/64=5) (65/74=6) (75/98=7) (99=.), gen(age_intervals)

	label define age_intervals ///
		1	"under 25" ///
		2 	"25-34 years" ///
		3 	"35-44 years" ///
		4 	"45-54 years" ///
		5	"55-64 years" ///
		6	"65-74 years" ///
		7	"75 and more"
	label values age_intervals age_intervals

	* Education
	recode DEGREE (0 1 2=1) (3 4=2) (5=3) (8 9=.), gen(education)
	label define degree ///
		1	"Primary or less" ///
		2	"Secondary" ///
		3	"Tertiary"
	label values education degree

	* Income
	* 1. generate exact numerical household/family income
		* A. directly use numerical variable (to the extent available)
		gen income = .
			// only available for: AR BG CN DE EE FI HR HU KR LT LV NO PH PL RU SE TR UA VE
			// declare missing values (where necessary)
			foreach ct in AR BG CN DE EE FI HR HU KR LT LV NO PH PL RU SE TR UA VE {
				replace income = `ct'_INC if country == "`ct'"
				replace income = . if country == "`ct'" & (income == 999997 | income == 9999998 | income == 999999)
			}
		* B. code numerical value from categorical income variable 
	
		// AT
		recode AT_INC (4000 = 5000) if country == "AT", gen(income_AT)
		// AU
		recode AU_INC (104000 = 130000) if country == "AU", gen(income_AU)
		// BE
		recode BE_INC (10450 = 12950) if country == "BE", gen(income_BE)
		// CH
		recode CH_INC (13000 = 15800) if country == "CH", gen(income_CH)
		// CL
		recode CL_INC (3100000 = 4000000) if country == "CL", gen(income_CL)
		// CY
		recode CY_INC (5980 = 7690) if country == "CY", gen(income_CY)
		// CZ
		recode CZ_INC (97500 = 100000) if country == "CZ", gen(income_CZ)
		// DK
		recode DK_INC (1050000 = 1100000) if country == "DK", gen(income_DK)
		// ES
		recode ES_INC (3000 = 3900) if country == "ES", gen(income_ES)
		// FR
		recode FR_INC (8250 = 9000) if country == "FR", gen(income_FR)
		// GB
		recode GB_INC (59000 = 59000) if country == "GB", gen(income_GB)
		// IL
		recode IL_INC (22000 = 24500) if country == "IL", gen(income_IL)
		// IS
		recode IS_INC (1300000 = 1400000) if country == "IS", gen(income_IS)
		// IT
		recode IT_INC (5500 = 6000) if country == "IT", gen(income_IT)
		// JP
		recode JP_INC (20000000 = 18000000) if country == "JP", gen(income_JP)
		// NZ
		recode NZ_INC (120000 = 120000) if country == "NZ", gen(income_NZ)
		// PT
		recode PT_INC (2500 = 3500) if country == "PT", gen(income_PT)
		// SI
		recode SI_INC (9996 = 12000) if country == "SI", gen(income_SI)
		// SK
		recode SK_INC (3000 = 4000) if country == "SK", gen(income_SK)
		// TW
		recode TW_INC (1250000 = 1500000) if country == "TW", gen(income_TW)
		// US
		recode US_INC (160000 = 170000) if country == "US", gen(income_US)
		// ZA
		recode ZA_INC (35000 = 40000) if country == "ZA", gen(income_ZA)
		// Add to existing container
		foreach ct in AT AU BE CH CL CY CZ DK ES FR GB IL IS IT JP NZ PT SI SK TW US ZA {
			replace income = income_`ct' if country == "`ct'"
			replace income = . if country == "`ct'" & (income == 999997 | income == 9999998 | income == 999999)
		}
	* 2. divide household income by square root of household size
		gen income_equi=income/(sqrt(HOMPOP)) if HOMPOP != 99
		
	* 3. code into quintiles
		egen income_equi_quint=xtile(income_equi), n(5) by(country)
		
	* 4. check whether this has worked
		bysort country: fre income_equi_quint

	* 5. code into deciles
		egen income_equi_dec=xtile(income_equi), n(10) by(country)
		
	* 6. check whether this has worked
		bysort country: fre income_equi_dec		

		
* keep variables
keep year country redistribution incdiffstoolarge income_equi* weight male age_intervals education tax_richvspoor

save "ISSP2009.dta", replace


******************************************************************************
********** Open ISSP Social Inequality data for round 5 (ISSP 2019) **********
******************************************************************************
use "ZA7600_v3-0-0.dta"

* Year
gen year=2019

***** Country identifiers 
fre country
fre c_alphan

	* Use two-letter country codes
	rename country country_orig
	clonevar country=c_alphan
	replace country="GB" if country=="GB-GBN"
	fre country
	// AT AU BG CH CL CZ DE DK FI FR GB HR IL IS IT JP LT NO NZ PH RU SE SI SR TH TW US VE ZA


***** Recoding of variables
	
	* Redistribution support (Q: "It is the responsibility of the government to reduce the differences in income between people with high incomes and those with low incomes")
	recode v22 (1=4) (2=3) (3=2) (4=1) (5=0) (-8 -9=.), gen(redistribution)
	
	* Income differences are too large (Q: "Differences in income in [COUNTRY] are too large")
	recode v21 (5=0) (4=1) (3=2) (2=3) (1=4) (-8 -9=.), gen(incdiffstoolarge)
	
	* Taxes for high vs. low incomes (Q: "Do you think that people with high incomes should pay a larger share of their income in taxes than those with low incomes, the same share, or a smaller share")
	recode v28 (5=0 "much smaller share") (4=1 "smaller share")  (3=2 "the same share")  (2=3 "larger share")  (1=4 "much larger share") (-8 -9=. ), gen(tax_richvspoor)
	
	* Weight
	clonevar weight=WEIGHT

	* Sex
	recode SEX (2=0) (-9=.), gen(male)

	* Age
	recode AGE (15/24=1) (25/34=2) (35/44=3) (45/54=4) (55/64=5) (65/74=6) (75/105=7) (-9=.), gen(age_intervals)

	label define age_intervals ///
		1	"under 25" ///
		2 	"25-34 years" ///
		3 	"35-44 years" ///
		4 	"45-54 years" ///
		5	"55-64 years" ///
		6	"65-74 years" ///
		7	"75 and more"
	label values age_intervals age_intervals

	* Education
	recode DEGREE (0 1 2=1) (3 4=2) (5 6=3) (-9=.), gen(education)

	label define degree ///
		1	"Primary or less" ///
		2	"Secondary" ///
		3	"Tertiary"
	label values education degree


	* Income
	* 1. generate exact numerical household/family income
		* A. directly use numerical variable (to the extent available)
		gen income = .
			// only available for: AU CZ FI FR LT PH RU SE SI TH VE
			// declare missing values (where necessary)
			foreach ct in AU CZ FI FR LT PH RU SE SI TH VE {
				replace income = `ct'_INC if `ct'_INC >= 0
			}
			
			* B. code numerical value from categorical income variable 
		
		// AT
		recode AT_INC (9000 = 10000) if country == "AT", gen(income_AT)
		// BG
		recode BG_INC (5000 = 6816) if country == "BG", gen(income_BG)
		// CH
		recode CH_INC (16800 = 18600) if country == "CH", gen(income_CH)
		// CL
		recode CL_INC (3100000 = 4000000) if country == "CL", gen(income_CL)
		// DE
		recode DE_INC (7500 = 10000) if country == "DE", gen(income_DE)
		// DK
		recode DK_INC (1150000 = 1200000) if country == "DK", gen(income_DK)
		// GB
		recode GB_INC (7200 = 7000) if country == "GB", gen(income_GB)
		// HR
		recode HR_INC (9000 = 11000) if country == "HR", gen(income_HR)
		// IL
		recode IL_INC (36000 = 38000) if country == "IL", gen(income_IL)
		// IS
		recode IS_INC (3900000 = 4300000) if country == "IS", gen(income_IS)
		// IT
		recode IT_INC (5000 = 5500) if country == "IT", gen(income_IT)
		// JP
		recode JP_INC (20000000 = 18000000) if country == "JP", gen(income_JP)
		// NO
		recode NO_INC (1667681 = 1902000) if country == "NO", gen(income_NO)
		// NZ
		recode NZ_INC (150000 = 200000) if country == "NZ", gen(income_NZ)
		// SR
		recode SR_INC (4500 = 5000) if country == "SR", gen(income_SR)
		// TW
		recode TW_INC (1250000 = 1500000) if country == "TW", gen(income_TW)
		// US
		recode US_INC (180000 = 190000) if country == "US", gen(income_US)
		// ZA
		recode ZA_INC (60000 = 70000) if country == "ZA", gen(income_ZA) 
		// Add to existing container
		foreach ct in AT BG CH CL DE DK GB HR IL IS IT JP NO NZ SR TW US ZA {
			replace income = `ct'_INC if `ct'_INC >= 0
		}
	* 2. divide household income by square root of household size
		gen income_equi=income/(sqrt(HOMPOP)) if HOMPOP >= 1
		
	* 3. code into quintiles
		egen income_equi_quint=xtile(income_equi), n(5) by(country)
		
	* 4. check whether this has worked
		bysort country: fre income_equi_quint

	* 6. code into deciles
		egen income_equi_dec=xtile(income_equi), n(10) by(country)
		
	* 7. check whether this has worked
		bysort country: fre income_equi_dec		
		
		
* keep variables
keep year country redistribution incdiffstoolarge income_equi* weight male age_intervals education tax_richvspoor

save "ISSP2019.dta", replace
clear 



******************************************************************************
**************** Append & Further Recode ISSP datasets *********************** 
******************************************************************************
use "ISSP2019.dta"
append using "ISSP2009.dta"
append using "ISSP1999.dta"
append using "ISSP1992.dta"
append using "ISSP1987.dta"


* create composite measure of support for redistribution-redistribution (factor)
factor redistribution tax_richvspoor incdiffstoolarge, pcf
gen redistribution_index=(redistribution+tax_richvspoor+incdiffstoolarge)/3

* rename year variable to year of ISSP survey variable
rename year year_ISSPwave

* merge variable with actual year in which survey took place 
	// first year coded if survey was in the field in two years
merge m:m country year_ISSPwave using "ISSP_surveyyears.dta", gen(merge_surveyyears)

rename year_survey year



***** Add technical variables *****
* create a trend variable
gen yeartrend=(year-1992)/100

* country groups
gen estdem = 0
replace estdem = 1 if country == "AT" | country == "AU" | country == "BE" | country == "CA" | country == "CH" | country == "DE" | country == "DK" ///
					| country == "ES" | country == "FI" | country == "FR" | country == "GB" | country == "IS" | country == "IT" | country == "IL" | country == "JP" | country == "NL" ///
					| country == "NO" | country == "NZ" | country == "PT" | country == "SE" | country == "US"				

* Create dummy for countries covered by all waves
gen allwaves = 0
replace allwaves = 1 if country == "AT" | country == "AU" | country == "DE" | country == "GB" | country == "US"

*** Create weight of 1 if weight is missing
replace weight=1 if weight==.


* save combined data from ISSP at individual level
save "ISSP_individual.dta", replace


*** collapse to country-year level
collapse (mean) redistribution redistribution_index incdiffstoolarge tax_richvspoor yeartrend estdem ///
		(last) year ///
		[iweight=weight], by(country year_ISSPwave)

* save combined data from ISSP, collapsed to the country-year level
save "ISSP_collapsed.dta", replace




**# Bookmark #3
********************************************************************************
*********** Merge individual-level ISSP data into macro data  ******************
********************************************************************************

* Merge combined individual ISSP dataset into combined macro dataset (mutiple imputation dataset)
clear 
use "MacroData.dta"
merge 1:m country year using "ISSP_individual.dta", gen(merge_ISSP_individual)


* create numerical country variable (so it is defined for all years - also those not covered by ISSP)
encode country, gen(country_id)

* label with country name
label define country_name ///
	1	 "Argentina" ///
	2 	 "Austria" ///
	3	 "Australia" ///
	4	 "Belgium" ///
	5	 "Bulgaria" ///
	6	 "Canada" ///
	7	 "Switzerland" ///
	8	 "Chile" ///
	9	 "China" ///
	10	 "Cyprus" ///
	11	 "Czechia" ///
	12	 "Germany" ///
	13	 "Denmark" ///
	14	 "Estonia" ///
	15	 "Spain" ///
	16	 "Finland" ///
	17	 "France" ///
	18	 "United Kingdom" ///
	19	 "Croatia" ///
	20	 "Hungary" ///
	21	 "Israel" ///
	22	 "Iceland" ///
	23	 "Italy" ///
	24	 "Japan" ///
	25	 "South Korea" ///
	26	 "Lithuania" ///
	27	 "Latvia" ///
	28	 "Netherlands" ///
	29	 "Norway" ///
	30	 "New Zealand" ///
	31	 "Philippines" ///
	32	 "Poland" ///
	33	 "Portugal" ///
	34	 "Russia" ///
	35	 "Sweden" ///
	36	 "Slovenia" ///
	37	 "Slovakia" ///
	38 	 "Suriname" ///
	39	 "Thailand" ///
	40	 "Turkey" ///
	41	 "Taiwan" ///
	42	 "Ukraine" ///
	43	 "United States of America" ///
	44	 "Venezuela" ///
	45	 "South Africa"
	
label values country_id country_name

decode country_id, gen(country_name)

sort country year

* create country-year variable 
capture drop CountryYear
egen CountryYear=concat(country year)



* Save final individual dataset 
save "Combined_individual.dta", replace



**# Bookmark #4
********************************************************************************
*********** Merge aggregate-level ISSP data into macro data  *******************
********************************************************************************

* Merge combined individual ISSP dataset into combined macro dataset (mutiple imputation dataset)
clear 
use "MacroData.dta"
merge 1:m country year using "ISSP_collapsed.dta", gen(merge_ISSP_collapsed)


* create numerical country variable (so it is defined for all years - also those not covered by ISSP)
encode country, gen(country_id)

* label with country name
label define country_name ///
	1	 "Argentina" ///
	2 	 "Austria" ///
	3	 "Australia" ///
	4	 "Belgium" ///
	5	 "Bulgaria" ///
	6	 "Canada" ///
	7	 "Switzerland" ///
	8	 "Chile" ///
	9	 "China" ///
	10	 "Cyprus" ///
	11	 "Czechia" ///
	12	 "Germany" ///
	13	 "Denmark" ///
	14	 "Estonia" ///
	15	 "Spain" ///
	16	 "Finland" ///
	17	 "France" ///
	18	 "United Kingdom" ///
	19	 "Croatia" ///
	20	 "Hungary" ///
	21	 "Israel" ///
	22	 "Iceland" ///
	23	 "Italy" ///
	24	 "Japan" ///
	25	 "South Korea" ///
	26	 "Lithuania" ///
	27	 "Latvia" ///
	28	 "Netherlands" ///
	29	 "Norway" ///
	30	 "New Zealand" ///
	31	 "Philippines" ///
	32	 "Poland" ///
	33	 "Portugal" ///
	34	 "Russia" ///
	35	 "Sweden" ///
	36	 "Slovenia" ///
	37	 "Slovakia" ///
	38 	 "Suriname" ///
	39	 "Thailand" ///
	40	 "Turkey" ///
	41	 "Taiwan" ///
	42	 "Ukraine" ///
	43	 "United States of America" ///
	44	 "Venezuela" ///
	45	 "South Africa"
	
label values country_id country_name

decode country_id, gen(country_name)

sort country year

* create country-year variable 
capture drop CountryYear
egen CountryYear=concat(country year)


**************** Compute difference variables (within countries over time) ********
	order country_id country year year_ISSPwave
	sort country_id year_ISSPwave

	* Compute gap in years to previous ISSP wave in country
	bysort country_id: gen year_diff=year-year[_n-1] if year_ISSPwave<.
	bysort country_id: gen year_ISSPwave_diff=year_ISSPwave-year_ISSPwave[_n-1] if year_ISSPwave<.
	
	* check for gaps between consecutive ISSP observations 
	fre year_diff
		// There are two cases with very long gaps of about twenty years in between two observations: Italy (19 years) and Switzerland (21 years) in ISSP 2009. 
		// These countries missed participation in waves in between.
		// For consistency and in order to prevent the length of the time periods from becoming too heterogeneous, we stick to the rule of using only consecutive observations between ISSP WAVES.
		// We therefore compute the change in redistribution support only if year_diff>15.
	
		*** Redistribution attitude			
			* Changes in mean attitudes towards redistribution
			bysort country_id: gen redist_change = redistribution-redistribution[_n-1] if year_diff<15 
			* Mean attitudes towards redistribution lag
			bysort country_id: gen redist_lag = redistribution[_n-1]
						
			* Changes in mean redistribution index
			bysort country_id: gen redistribution_index_change = redistribution_index-redistribution_index[_n-1] if year_diff<15 
			* Redistribution index lag
			bysort country_id: gen redistribution_index_lag = redistribution_index[_n-1]				
							
			* Changes in mean attitudes towards taxes for rich vs poor
			bysort country_id: gen tax_change = tax_richvspoor-tax_richvspoor[_n-1] if year_diff<15 

			* Changes in mean attitudes towards "perceived income differences are too large"
			bysort country_id: gen incdiffstoolarge_change = incdiffstoolarge-incdiffstoolarge[_n-1] if year_diff<15 			
			
			
		*** Corresponding changes in Gini
			* imputed variables:
			mi passive: by country_id: gen Gini_disp_change = Gini_disp-Gini_disp[_n-1] if year_ISSPwave<.
			mi passive: by country_id: gen Gini_disp_lag = Gini_disp[_n-1] if year_ISSPwave<. 	
						
			mi passive: by country_id: gen Gini_mkt_change = Gini_mkt-Gini_mkt[_n-1] if year_ISSPwave<. 
			mi passive: by country_id: gen Gini_redis_change = Gini_redis-Gini_redis[_n-1] if year_ISSPwave<. 
				
			* posterior mean
			by country_id: gen Gini_disp_pm_change = Gini_disp_pm-Gini_disp_pm[_n-1] if year_ISSPwave<. 
			by country_id: gen Gini_disp_pm_lag = Gini_disp_pm[_n-1] if year_ISSPwave<. 
			
				* Standard error for first difference in posterior mean
				by country_id: gen Gini_disp_pm_change_SE = sqrt((Gini_disp_se*Gini_disp_se)+(Gini_disp_se[_n-1]*Gini_disp_se[_n-1])) if year_ISSPwave<. 

				gen Gini_disp_pm_change_ub_SE=Gini_disp_pm_change+1*Gini_disp_pm_change_SE
				gen Gini_disp_pm_change_lb_SE=Gini_disp_pm_change-1*Gini_disp_pm_change_SE

				
		*** Corresponding changes in top income shares
				bysort country_id: gen sptincp90p100_change = sptincp90p100-sptincp90p100[_n-1] if year_ISSPwave<. 

				
		*** Corresponding changes in control variables
				* Corresponding changes in GDPpc (GDP per capita (constant 2015 US$))
				gen gdp_capita_con=ny_gdp_pcap_kd
				bysort country_id: gen gdp_capita_con_change = gdp_capita_con-gdp_capita_con[_n-1] if year_ISSPwave<. 
				
				* Corresponding growth rate in GDPpc (GDP per capita (constant 2015 US$))
				bysort country_id: gen gdp_capita_con_growth = (gdp_capita_con-gdp_capita_con[_n-1])/gdp_capita_con[_n-1] if year_ISSPwave<. 

				* Net migration
				sort country_id year
				
				gen netmigr=sm_pop_netm
				order netmigr
				
				gen netmigr_cum=netmigr if year_ISSPwave[_n-1]<.
					order netmigr_cum
				
				bysort country_id: replace netmigr_cum=netmigr_cum[_n-1]+netmigr[_n] if netmigr_cum[_n-1]<. & year_ISSPwave[_n-1]==.
				
				gen population=sp_pop_totl
				gen netmigr_cum_bypop=netmigr_cum/population if year_ISSPwave[_n]<.
					order netmigr_cum_bypop
					
				* Corresponding change in inflation
				gen inflation=fp_cpi_totl_zg 
				bysort country_id: gen inflation_change = inflation-inflation[_n-1] if year_ISSPwave<. 
		
				* Corresponding change in tax revenue in % of GDP
				gen taxrevenue=gc_tax_totl_gd_zs 
				bysort country_id: gen taxrevenue_change = taxrevenue-taxrevenue[_n-1] if year_ISSPwave<. 
				
				* Corresponding change in unemployment rate (Unemployment, total (% of total labor force) (national estimate))
				gen unemployment=sl_uem_totl_zs
				bysort country_id: gen unemployment_change = unemployment-unemployment[_n-1] if year_ISSPwave<. 				
		
		
		* count valid observations with redistribution attitude
		gen redistr_valid=1 if redistribution!=.
		bysort country: egen caseno_redistr=sum(redistr_valid)
		sort year
		
		
	* Save final collapsed dataset 
	save "Combined_collapsed.dta", replace		

	
log using reproduction, replace

**# Bookmark #5	
********************************************************************************		
********************* Descriptive Graphs ***************************************
********************************************************************************


*** Histogram with redistribution attitude
use "Combined_individual.dta"

histogram redistribution , discrete percent ///
	xtitle("It is the responsibility of government to reduce the differences in income between people with high incomes and those with low incomes", size(vsmall)) ///
	xscale(range(0 4)) xlabel(0 "strongly disagree" 1 "disagree" 2 "neither" 3 "agree" 4 "strongly agree", angle(45)) ///
	by(year_ISSPwave, total rows(1) note("") legend(off)) addlabel addlabopts(mlabsize(small) mlabgap(-0.5) yvarformat(%9.1g)) ///
	name(FigureC1, replace)
				
	graph export "FigureC1.pdf", replace
	graph export "FigureC1.jpg", width(5000) replace

		

*** Lineplot: Inequality and attitudes towards redistribution over time
use "Combined_collapsed.dta"
	
	*** Figure: Mean support for redistribution and Gini index of disposable income
		* only countries with at least two observations
		preserve
		keep if caseno_redistr>=2
		replace country_name="USA" if country_name=="United States of America"
		codebook country_name
		
	twoway (connected redistribution year, by(country_name, legend(off)) msymbol(+) mcolor(dknavy) lcolor(dknavy) ytitle("Mean support for redistribution", color(dknavy) size(small)) xtitle("Year")) /// 
		(line Gini_disp_pm year, by(country_name, rows(5) imargin(tiny) note("") r1title("Gini index of disposable income", color(orange_red) size(small))) lpattern(solid) lcolor(orange_red) yaxis(2)) ///
		(line Gini_disp_95ub year, by(country_name) lpattern(shortdash) lcolor(orange_red) yaxis(2)) ///
		(line Gini_disp_95lb year, by(country_name) lpattern(shortdash) lcolor(orange_red) yaxis(2)) ///
		, xlabel(1990 (10) 2025, angle(090)) xmticks(1985 (5) 2020) ylabel(.1 (.1) .7, axis(2)) ///
		ysize(6) scale(1.4) name(FigureC2, replace)
			
	graph export "FigureC2.pdf", replace		
	graph export "FigureC2.jpg", width(5000) replace
	
	restore	
			

*** Scatterplots: Changes: Mean support for redistribution and Gini index of disposable income
		* Correlations: Change in redistribution attitudes and change in inequality
		pwcorr redist_change Gini_disp_pm_change, obs sig 	
				
		* Define dummy for observations to be markered
		gen markdummy=1 if (abs(Gini_disp_pm_change)>.028 | redist_change>0.4 | redist_change<-0.3)
		replace markdummy=1 if CountryYear=="DE2000"
		replace markdummy=1 if CountryYear=="PH2019"
		replace markdummy=1 if CountryYear=="GB2009"
		replace markdummy=1 if CountryYear=="PL2020"
		replace markdummy=1 if CountryYear=="NZ2020"
		replace markdummy=1 if CountryYear=="CL2019"
		replace markdummy=1 if CountryYear=="NO2020"
		replace markdummy=1 if CountryYear=="DE1992"
		replace markdummy=1 if CountryYear=="US2010"
		replace markdummy=1 if CountryYear=="BG2008"
		replace markdummy=1 if CountryYear=="FR2009"
		replace markdummy=1 if CountryYear=="SE1999"
		replace markdummy=1 if CountryYear=="PT2009"
		replace markdummy=1 if CountryYear=="CZ2008"
		replace markdummy=1 if CountryYear=="GB2019"
		replace markdummy=1 if CountryYear=="TW2019"
		replace markdummy=1 if CountryYear=="PL2010"
		replace markdummy=1 if CountryYear=="HU1999"
		replace markdummy=1 if CountryYear=="AT2021"
		
		* Define variable for marker positions
		gen markpos=1
		replace markpos=11 if CountryYear=="FR2021"
		replace markpos=4 if CountryYear=="DE2000"
		replace markpos=2 if CountryYear=="GB2009"
		replace markpos=4 if CountryYear=="PL2020"
		replace markpos=11 if CountryYear=="NZ2020"
		replace markpos=8 if CountryYear=="CL2019"
		replace markpos=2 if CountryYear=="N02020"
		replace markpos=6 if CountryYear=="DE1992"
		replace markpos=2 if CountryYear=="US2010"
		replace markpos=4 if CountryYear=="BG2008"
		replace markpos=11 if CountryYear=="FR2009"
		replace markpos=2 if CountryYear=="SE1999"
		replace markpos=4 if CountryYear=="PT2009"
		replace markpos=3 if CountryYear=="CZ2008"
		replace markpos=8 if CountryYear=="GB2019"
		replace markpos=4 if CountryYear=="TW2019"
		replace markpos=4 if CountryYear=="PL2010"
		replace markpos=2 if CountryYear=="HU1999"
		replace markpos=11 if CountryYear=="AT2021"
		
		replace markpos=4 if CountryYear=="AT1993"
		replace markpos=8 if CountryYear=="CL2009"
		replace markpos=4 if CountryYear=="HU1992"
		replace markpos=4 if CountryYear=="SK1999"
		replace markpos=2 if CountryYear=="BG2021"
		
		
		* Create scatterplot
		twoway (lfit redist_change Gini_disp_pm_change, text(-.375 0.055 "r=0.37, p=0.002 (n=71)", size(small))) ///
			///
			(rspike  Gini_disp_pm_change_ub_SE Gini_disp_pm_change_lb_SE redist_change, horizontal lstyle(ci) lcolor(orange_red%20)) ///
			///
			(scatter redist_change Gini_disp_pm_change, ///
			mcolor(orange_red) msymbol(dh) yline(0) xline(0))  ///
			///
			(scatter redist_change Gini_disp_pm_change if markdummy==1, ///
			mcolor(orange_red) msymbol(dh) mlabel(CountryYear) mlabsize(tiny) mlabcolor(gs10) mlabgap(*.1) mlabvpos(markpos) yline(0) xline(0)  ///
			xscale(range(-.04 .08)) xlabel(-.1 (.02) .1) ylabel(-.4 (.2) .8, gmin gmax)), ///
			///
			legend(off) ///
			ytitle("Change in redistribution support", size(small)) ///
			xtitle("Change in disposable income Gini", size(small)) ///
			title(" ", size(small)) ///
			scale(*1.3) ///
			name(Figure1, replace)		
			
			graph export "Figure1.pdf", replace			
			graph export "Figure1.jpg", width(5000) replace

	
	
**# Bookmark #6	
********************************************************************************			
********************* Regressions with aggregated data: Main *******************
********************************************************************************
clear

use "Combined_collapsed.dta"
order country_id year
sort country_id year

	
*** Gini index, disposable income

		*** All countries
		* Plus trend
		mi estimate, post: reg redist_change Gini_disp_change c.yeartrend##c.yeartrend, cluster(country)
		eststo m1
		
			mibeta redist_change Gini_disp_change c.yeartrend##c.yeartrend, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redist_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m2
		
			mibeta redist_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)		
		
		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m3
		
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)		
		
		*** Liberal democracies only
		* Plus trend
		mi estimate, post: reg redist_change Gini_disp_change c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m4
		
			mibeta redist_change Gini_disp_change c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<.
			
		* Plus substantive controls
		mi estimate, post: reg redist_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m5
		
			mibeta redist_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		
		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m6
		
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		
		*** Advanced democracies only
		* Plus trend
		mi estimate, post: reg redist_change Gini_disp_change c.yeartrend##c.yeartrend if estdem==1, cluster(country)
		eststo m7
		
			mibeta redist_change Gini_disp_change c.yeartrend##c.yeartrend if estdem==1, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redist_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m8
		
			mibeta redist_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
	
		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m9		
		
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
			
		// de facto included: 
			// Austria, Australia, Canada, Denmark, Germany
			// Finland, France, Israel, Italy, Japan
			// Norway, New Zealand, Portugal, Sweden
			// Spain, UK, USA	
					
		*** Regression Table
			esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 using "Table1.rtf" ///
				, b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps nomtitles compress ///
				scalars(r2) replace 					


				
**# Bookmark #7
********************************************************************************			
********************* Regressions with aggregated data: Robustness *************
********************************************************************************
					
					
********************* Table D1: Bivariate first-difference regressions of support for redistribution *************************
		clear
		
		use "Combined_collapsed.dta"
		order country_id year
		sort country_id year

		
		*** All countries
		* Bivariate
		mi estimate, post: reg redist_change Gini_disp_change, cluster(country)
		eststo m1

			mibeta redist_change Gini_disp_change, cluster(country)
			
		*** Liberal democracies only
		* Bivariate
		mi estimate, post: reg redist_change Gini_disp_change if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m2
		
			mibeta redist_change Gini_disp_change if v2x_regime>2 & v2x_regime<., cluster(country)

		*** Advanced democracies only
		* Bivariate
		mi estimate, post: reg redist_change Gini_disp_change if estdem==1, cluster(country)
		eststo m3
		
			mibeta redist_change Gini_disp_change if estdem==1, cluster(country)

			
		*** Regression Table
		esttab m1 m2 m3 using "TableD1.rtf" ///
			, b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps nomtitles compress ///
			scalars(r2) replace 						
			
			
			
					
********************* Table D2: First-difference regressions of support for redistribution with posterior mean of the Gini (with conventional clustered SEs and wild cluster bootstrap) *************************
					
					
********************* with ordinary clustered SEs
		
		*** All countries
		* Plus trend
		reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend, cluster(country)
		eststo m1
						
		* Plus substantive controls
		reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m2

		* Plus substantive controls and lagged redistribution support
		reg redist_change Gini_disp_pm_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m3

		*** Liberal democracies only		
		* Plus trend
		reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m4
						
		* Plus substantive controls
		reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m5
				
		* Plus substantive controls and lagged redistribution support
		reg redist_change Gini_disp_pm_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m6
					
		*** Established democracies only
		* Plus trend
		reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend if estdem==1, cluster(country)
		eststo m7
						
		* Plus substantive controls
		reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m8
							
		* Plus substantive controls and lagged redistribution support
		reg redist_change Gini_disp_pm_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m9		
							
		*** Regression Table
		esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 using "TableD2_clusteredSEs.rtf" ///
			, b(a2) p(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps nomtitles compress ///
			scalars(r2) replace 			

						

********************* Wild cluster bootstrap 
		
		*** All countries
		* Plus trend
		wildbootstrap reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend, cluster(country) rseed(12345)
		eststo m1
					
		* Plus substantive controls
		wildbootstrap reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country) rseed(12345)
		eststo m2
				
		* Plus substantive controls and lagged redistribution support
		wildbootstrap reg redist_change Gini_disp_pm_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country) rseed(12345)
		eststo m3 
		
		*** Liberal democracies only
		* Plus trend
		wildbootstrap reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<., cluster(country) rseed(12345)
		eststo m4
					
		* Plus substantive controls
		wildbootstrap reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country) rseed(12345)
		eststo m5
		
		* Plus substantive controls and lagged redistribution support
		wildbootstrap reg redist_change Gini_disp_pm_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country) rseed(12345)
		eststo m6
				
		*** Established democracies only
		* Plus trend
		wildbootstrap reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend if estdem==1, cluster(country) rseed(12345)
		eststo m7
					
		* Plus substantive controls
		wildbootstrap reg redist_change Gini_disp_pm_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country) rseed(12345)
		eststo m8		
					
		* Plus substantive controls and lagged redistribution support
		wildbootstrap reg redist_change Gini_disp_pm_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country) rseed(12345)
		eststo m9		
			
		*** p-values entered manually in regression Table D2								
					
					
					
********************* Table D3: First-difference regressions of support for redistribution with additional control variables *************************
					
	*** All countries
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop inflation_change, cluster(country)
		eststo m1
		
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop inflation_change, cluster(country)
		
		
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop unemployment_change, cluster(country)
		eststo m2
	
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop unemployment_change, cluster(country)
		
		
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop taxrevenue_change, cluster(country)
		eststo m3
	
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop taxrevenue_change, cluster(country)
		
		
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop inflation_change unemployment_change taxrevenue_change, cluster(country)
		eststo m4
	
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop inflation_change unemployment_change taxrevenue_change, cluster(country)
			
		
		*** Liberal democracies only
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop inflation_change if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m5
	
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop inflation_change if v2x_regime>2 & v2x_regime<., cluster(country)
					
					
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop unemployment_change if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m6
	
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop unemployment_change if v2x_regime>2 & v2x_regime<., cluster(country)
					
					
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop taxrevenue_change if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m7
	
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop taxrevenue_change if v2x_regime>2 & v2x_regime<., cluster(country)
			
			
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop inflation_change unemployment_change taxrevenue_change if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m8
	
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop inflation_change unemployment_change taxrevenue_change if v2x_regime>2 & v2x_regime<., cluster(country)
		
		
		*** Regression Table
			esttab m1 m2 m3 m4 m5 m6 m7 m8 using "TableD3.rtf" ///
				, b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps nomtitles compress ///
				scalars(r2) replace 			
										

										
										
********************* Table D4: First-difference regressions of support for redistribution controlling for the lagged Gini coefficient *************************
									
	
*** Correlation between change in Gini and lagged Gini
	pwcorr Gini_disp_pm_change Gini_disp_pm_lag	redist_lag	
		

		*** All countries
		* Plus trend
		mi estimate, post: reg redist_change Gini_disp_change Gini_disp_lag c.yeartrend##c.yeartrend, cluster(country)
		eststo m1
		
			mibeta redist_change Gini_disp_change Gini_disp_lag c.yeartrend##c.yeartrend, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redist_change Gini_disp_change Gini_disp_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m2
		
			mibeta redist_change Gini_disp_change Gini_disp_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)		
			
		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change Gini_disp_change Gini_disp_lag redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m3
		
			mibeta redist_change Gini_disp_change Gini_disp_lag redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)		
		
		*** Liberal democracies only	
		* Plus trend
		mi estimate, post: reg redist_change Gini_disp_change Gini_disp_lag c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m4
		
			mibeta redist_change Gini_disp_change Gini_disp_lag c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<.
			
		* Plus substantive controls
		mi estimate, post: reg redist_change Gini_disp_change Gini_disp_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m5
		
			mibeta redist_change Gini_disp_change Gini_disp_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
			
		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change Gini_disp_change Gini_disp_lag redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m6
		
			mibeta redist_change Gini_disp_change Gini_disp_lag redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		
		*** Established democracies only
		* Plus trend
		mi estimate, post: reg redist_change Gini_disp_change Gini_disp_lag c.yeartrend##c.yeartrend if estdem==1, cluster(country)
		eststo m7
		
			mibeta redist_change Gini_disp_change Gini_disp_lag c.yeartrend##c.yeartrend if estdem==1, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redist_change Gini_disp_change Gini_disp_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m8		
		
			mibeta redist_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
			
		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change Gini_disp_change Gini_disp_lag redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m9		
		
			mibeta redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
				
		*** Regression Table
			esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 using "TableD4.rtf" ///
				, b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps nomtitles compress ///
				scalars(r2) replace 						
					
					
					
					
********************* Figure D1: Leaving out individual ISSP waves  *************************
					
	mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
			eststo all

		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if year_ISSPwave!=1992, cluster(country)
			eststo wo1992
		
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if year_ISSPwave!=1999, cluster(country)
			eststo wo1997

		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if year_ISSPwave!=2009, cluster(country)
			eststo wo2009
		
		mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if year_ISSPwave!=2019, cluster(country)
			eststo wo2019

	coefplot (all\ wo1992 \ wo1997 \ wo2009 \ wo2019), ///
		keep(Gini_disp_change) xline(0) level(95 90) aseq swapnames ///
		mlabel format(%9.2f) mlabposition(12) mlabgap(*2) ///
			coeflabels( all = "all ISSP waves (model 3, Table 1)" ///
			   wo1992 = "without ISSP 1992" ///
               wo1997 = "without ISSP 1999"  ///
               wo2009 = "without ISSP 2009" ///
               wo2019 = "without ISSP 2019")  ///
  			   xlabel(-2 "-2" 0 ".0" 2 "2" 4 "4" 6 "6", gmin gmax) ///
			   scale(*1.4) xsize(7) ///
			   name(FigureD1, replace)
			
		graph export "FigureD1.pdf", replace			
		graph export "FigureD1.jpg", width(5000) replace

			
			
********************* Figure D2: Leaving out individual countries  *************************

		reg redist_change Gini_disp_pm_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		
			levelsof country if e(sample), local(countries)

			foreach country of local countries{
			display "`country'"
			mi estimate, post: reg redist_change Gini_disp_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if country!="`country'", cluster(country)
			eststo `country'				
			}
			
		coefplot (all \ AT \ AU \ BG \ CA \ CH \ CL \ CY \ CZ \ DE \ DK \ ES \ FI \ FR \ GB \ HR \ HU \ IL \ IT \ JP \ LT \ LV \ NO \ NZ \ PH \ PL \ PT \ RU \ SE \ SI \ SK \ US), ///
		keep(Gini_disp_change) xline(0) level(95 90) aseq swapnames ///
		mlabel format(%9.2f) mlabposition(0) mlabgap(*0) ///
			coeflabels( all = "all countries (model 3, Table 1)" ///
			   AT = "Austria" ///
               AU = "Australia" ///
               BG = "Bulgaria" ///
			   CA = "Canada" ///
               CH = "Switzerland" ///
               CL = "Chile" ///
 			   CY = "Cyprus" ///
               CZ = "Czech Republic" ///
               DE = "Germany" ///              
 			   DK = "Denmark" ///
               ES = "Spain" ///
               FI = "Finland" ///              
   			   FR = "France" ///
               GB = "United Kingdom" ///
               HR = "Croatia" ///              
			   HU = "Hungary" ///
               IL = "Israel" ///
               IT = "Italy" ///
			   JP = "Japan" ///
               LT = "Lithuania" ///
               LV = "Latvia" ///
 			   NO = "Norway" ///
 			   NZ = "New Zealand" ///			   
               PH = "Philippines" ///
               PL = "Poland" ///              
 			   PT = "Portugal" ///
               RU = "Russia" ///
               SE = "Sweden" ///              
   			   SI = "Slovenia" ///
               SK = "Slovakia" ///
               US = "United States" ) ///
  			   xlabel(-2 "-2" 0 ".0" 2 "2" 4 "4" 6 "6", gmin gmax) ///
			   scale(*1.1) ysize(6) ///
			   name(FigureD2, replace)		
			 
			graph export "FigureD2.pdf", replace			
			graph export "FigureD2.jpg", width(5000) replace
								
					
					

********************* Table D5: Country fixed effects regressions of support for redistribution *************************
			
	* Note: For models 3, 6 and 9, we now use the level version of the controls (gdp_capita_con & netmigr)
	
		gen countryonlyonce=1 if country == "UA" | country == "TR" | country == "TH" | country == "SR" | country == "NL" | country == "KR" | country == "EE" | country == "CN" | country == "BE" | country == "AR"
	
	* We measure net migration (in the given year) as a share of the population 
	gen netmigr_bypop=netmigr/population
	
	* We take the natural logarithm of GDP per capita
	gen gdp_capita_con_ln=ln(gdp_capita_con)

		
*** Gini index, disposable income

		*** All countries
		* Bivariate
		mi estimate, post: reg redistribution Gini_disp i.country_id if countryonlyonce!=1, cluster(country)
		
			mibeta redistribution Gini_disp i.country_id if countryonlyonce!=1, cluster(country)
	
		* Plus trend
		mi estimate, post: reg redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend if countryonlyonce!=1, cluster(country)
		eststo m1
		
			mibeta redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend if countryonlyonce!=1, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend gdp_capita_con_ln netmigr_bypop if countryonlyonce!=1, cluster(country)
		eststo m2
		
			mibeta redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend gdp_capita_con_ln netmigr_bypop if countryonlyonce!=1, cluster(country)		
		
		*** Liberal democracies only
		* Bivariate
		mi estimate, post: reg redistribution Gini_disp i.country_id if countryonlyonce!=1 & v2x_regime>2 & v2x_regime<., cluster(country)
		
			mibeta redistribution Gini_disp i.country_id if countryonlyonce!=1 & v2x_regime>2 & v2x_regime<., cluster(country)
			
		* Plus trend
		mi estimate, post: reg redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend if countryonlyonce!=1 & v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m3
		
			mibeta redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend if countryonlyonce!=1 & v2x_regime>2 & v2x_regime<.
			
		* Plus substantive controls
		mi estimate, post: reg redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend gdp_capita_con_ln netmigr_bypop if countryonlyonce!=1 & v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m4
		
			mibeta redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend gdp_capita_con_ln netmigr_bypop if countryonlyonce!=1 & v2x_regime>2 & v2x_regime<., cluster(country)
		
		*** Advanced democracies only
		* Bivariate
		mi estimate, post: reg redistribution Gini_disp i.country_id if countryonlyonce!=1 & estdem==1, cluster(country)
		
			mibeta redistribution Gini_disp i.country_id if countryonlyonce!=1 & estdem==1, cluster(country)
			
		* Plus trend
		mi estimate, post: reg redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend if countryonlyonce!=1 & estdem==1, cluster(country)
		eststo m5
		
			mibeta redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend if countryonlyonce!=1 & estdem==1, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend gdp_capita_con_ln netmigr_bypop if countryonlyonce!=1 & estdem==1, cluster(country)
		eststo m6		
		
			mibeta redistribution Gini_disp i.country_id c.yeartrend##c.yeartrend gdp_capita_con_ln netmigr_bypop if countryonlyonce!=1 & estdem==1, cluster(country)
			
			
		*** Regression Table
			esttab m1 m2 m3 m4 m5 m6 using "TableD5.rtf" ///
				, b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps nomtitles compress ///
				scalars(r2) replace 	
									
			
			
			
********************* Table D6: First-difference regressions of support for redistribution with interactions with country groups *************************

		gen EasternEurope=0 
			replace EasternEurope=1 if countryname=="Bulgaria" | countryname=="Croatia" | countryname=="Czech Republic" | countryname=="Estonia" | countryname=="Hungary" | countryname=="Latvia" | ///
								   countryname=="Lithuania" | countryname=="Poland" |  countryname=="Russian Federation" | countryname=="Slovakia" | countryname=="Slovenia" | countryname=="Ukraine" 
		
		generate country_group=.
		replace country_group=0 if estdem==1
		replace country_group=1 if EasternEurope==1
		replace country_group=2 if estdem!=1 & EasternEurope!=1
		
		label define country_group 0 "advanced democracy" 1 "Eastern Europe" 2 "other" 
		label values country_group country_group

			* Plus trend
			mi estimate, post: reg redist_change c.Gini_disp_change##i.country_group c.yeartrend##c.yeartrend, cluster(country)
			eststo m10
					
				mibeta redist_change c.Gini_disp_change##i.country_group c.yeartrend##c.yeartrend, cluster(country) 
				
			* Plus substantive controls
			mi estimate, post: reg redist_change c.Gini_disp_change##i.country_group c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
			eststo m11		
				
				mibeta redist_change c.Gini_disp_change##i.country_group c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
			
			* Plus substantive controls and lagged redistribution support
			mi estimate, post: reg redist_change c.Gini_disp_change##i.country_group redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
			eststo m12		
				
				mibeta redist_change c.Gini_disp_change##i.country_group redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
			
		*** Regression Table
			esttab m10 m11 m12 using "TableD6.rtf" ///
				, b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps nomtitles compress ///
				scalars(r2) replace 					
	
	

			
********************* Table D7: First-difference regressions of support for redistribution with market income Gini *************************
				
		*** All countries
		* Plus trend
		mi estimate, post: reg redist_change Gini_mkt_change c.yeartrend##c.yeartrend, cluster(country)
		eststo m1
		
			mibeta redist_change Gini_mkt_change c.yeartrend##c.yeartrend, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redist_change Gini_mkt_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m2
		
			mibeta redist_change Gini_mkt_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)		

		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change Gini_mkt_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m3
		
			mibeta redist_change Gini_mkt_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)		

			
		*** Liberal democracies only
		* Plus trend
		mi estimate, post: reg redist_change Gini_mkt_change c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m4
		
			mibeta redist_change Gini_mkt_change c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<.
			
		* Plus substantive controls
		mi estimate, post: reg redist_change  Gini_mkt_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m5
		
			mibeta redist_change Gini_mkt_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)

		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change  Gini_mkt_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m6
		
			mibeta redist_change Gini_mkt_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		
		*** Advanced democracies only
		* Plus trend
		mi estimate, post: reg redist_change Gini_mkt_change c.yeartrend##c.yeartrend if estdem==1, cluster(country)
		eststo m7
		
			mibeta redist_change Gini_mkt_change c.yeartrend##c.yeartrend if estdem==1, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redist_change Gini_mkt_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m8	
		
			mibeta redist_change Gini_mkt_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)

		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change Gini_mkt_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m9		
		
			mibeta redist_change Gini_mkt_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
					
		*** Regression Table
			esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 using "TableD7.rtf" ///
				, b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps nomtitles compress ///
				scalars(r2) replace 					
								


********************* Table D8: First-difference regressions of support for redistribution with pre-tax top 10% income share *************************

		*** All countries
		* Plus trend
		reg redist_change sptincp90p100_change c.yeartrend##c.yeartrend, cluster(country)
		eststo m1
					
		* Plus substantive controls
		reg redist_change sptincp90p100_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m2
		
		* Plus substantive controls and lagged redistribution support
		reg redist_change sptincp90p100_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m3
				
		*** Liberal democracies only
		* Plus trend
		reg redist_change sptincp90p100_change c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m4
					
		* Plus substantive controls
		reg redist_change sptincp90p100_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m5
		
		* Plus substantive controls and lagged redistribution support
		reg redist_change sptincp90p100_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m6
		
		*** Established democracies only
		* Plus trend
		reg redist_change sptincp90p100_change c.yeartrend##c.yeartrend if estdem==1, cluster(country)
		eststo m7

		* Plus substantive controls
		reg redist_change sptincp90p100_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m8
		
		* Plus substantive controls and lagged redistribution support
		reg redist_change sptincp90p100_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m9		
		
					
		*** Regression Table
			esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 using "TableD8.rtf" ///
				, b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps nomtitles compress ///
				scalars(r2) replace 											
		

		
		
********************* Table D9: First-difference regressions of support for redistribution with market income Gini and absolute redistribution  *************************
		*** All countries
		* Plus trend
		mi estimate, post: reg redist_change Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend, cluster(country)
		eststo m1
		
			mibeta redist_change Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redist_change Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m2
		
			mibeta redist_change Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)		
		
		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change Gini_mkt_change Gini_redis_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m3
		
			mibeta redist_change Gini_mkt_change Gini_redis_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)		
		
		*** Liberal democracies only
		* Plus trend
		mi estimate, post: reg redist_change Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m4
		
			mibeta redist_change Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<.
			
		* Plus substantive controls
		mi estimate, post: reg redist_change  Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m5
		
			mibeta redist_change Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		
		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change  Gini_mkt_change Gini_redis_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m6
		
			mibeta redist_change Gini_mkt_change Gini_redis_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		
		*** Advanced democracies only
		* Plus trend
		mi estimate, post: reg redist_change Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend if estdem==1, cluster(country)
		eststo m7
		
			mibeta redist_change Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend if estdem==1, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redist_change Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m8
		
			mibeta redist_change Gini_mkt_change Gini_redis_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		
		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redist_change Gini_mkt_change Gini_redis_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m9		
		
			mibeta redist_change Gini_mkt_change Gini_redis_change redist_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)

					
		*** Regression Table
			esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 using "TableD9.rtf" ///
				, b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps nomtitles compress ///
				scalars(r2) replace 					
															
		mi estimate, post: regress Gini_redis_change Gini_mkt_change if redist_change<., cluster(country)
						
				mibeta Gini_redis_change Gini_mkt_change if redist_change<., cluster(country)
				
		mi estimate, post: regress Gini_disp_change Gini_redis_change Gini_mkt_change if redist_change<., cluster(country)

					mibeta Gini_disp_change Gini_redis_change Gini_mkt_change if redist_change<., cluster(country)
		
	
		
**# Bookmark #8	
********************************************************************************		
****************************** Multilevel models: Main *************************
********************************************************************************		
	clear
	use "Combined_individual.dta"
	
	
	* count valid observations with redistribution attitude
	gen redistr_valid=1 if redistribution!=.
	bysort country: fre year if year_ISSPwave<.
	
	gen countryonlyonce=1 if country == "UA" | country == "TR" | country == "TH" | country == "SR" | country == "NL" | country == "KR" | country == "EE" | country == "CN" | country == "BE" | country == "AR"
	drop if countryonlyonce==1
	
	
	***** Estimate ML models
	*** All countries
	* M1: random intercept model (multiple imputation)
	mi estimate, post dots: mixed redistribution Gini_disp c.yeartrend##c.yeartrend i.income_equi_quint i.male i.age_intervals i.education i.country_id  || CountryYear:, stddeviations
		eststo ML1
		estimates save ML1, replace
		
	* M2: random intercept model (posterior mean)
	mixed redistribution Gini_disp_pm c.yeartrend##c.yeartrend i.income_equi_quint i.male i.age_intervals i.education i.country_id  || CountryYear:, stddeviations
		estat ic
		eststo ML2

	* M3: random slope model with cross-level interaction with income and with education (posterior mean)
	mixed redistribution c.Gini_disp_pm##i.income_equi_quint c.Gini_disp_pm##i.education c.yeartrend##c.yeartrend i.male i.age_intervals i.country_id || CountryYear: i.income_equi_quint i.education, stddeviations
		estat ic
		eststo ML3
		
		
	*** Liberal democracies only
	* M4: random intercept model (multiple imputation)
	mi estimate, post dots: mixed redistribution Gini_disp c.yeartrend##c.yeartrend i.income_equi_quint i.male i.age_intervals i.education i.country_id if v2x_regime>2 & v2x_regime<. || CountryYear:, stddeviations
		eststo ML4
		estimates save ML4, replace
			
	* M5: random intercept model (posterior mean)
	mixed redistribution Gini_disp_pm c.yeartrend##c.yeartrend i.income_equi_quint i.male i.age_intervals i.education i.country_id if v2x_regime>2 & v2x_regime<. || CountryYear:, stddeviations
		estat ic
		eststo ML5

	* M6: random slope model with cross-level interaction with income and with education (posterior mean)
	mixed redistribution c.Gini_disp_pm##i.income_equi_quint c.Gini_disp_pm##i.education c.yeartrend##c.yeartrend i.male i.age_intervals i.country_id if v2x_regime>2 & v2x_regime<. || CountryYear: i.income_equi_quint i.education, stddeviations
		estat ic
		eststo ML6

	* Regression Table		
	esttab ML1 ML2 ML3 ML4 ML5 ML6 ///
		using "TableE1.rtf", b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps compress ///
		replace ///
		label scalars(r2) transform(ln*: exp(@) exp(@))		
		
		
		
	***** Figure 2: Inequality, income quintile and support for redistribution 
		*** Model 3
		estimates restore ML3
		
		* Conditional effect plot	
		margins, dydx(Gini_disp_pm) at(income_equi_quint=(1/5)) post
			eststo ML3_marg

		coefplot ///
			(ML3_marg, msymbol(+) mcolor(black) level(95 85) ciopts(color(black black))), ///
			ylabel(0 (1) 5, gmin gmax) vertical ///
			xtitle("income quintile") ytitle("support for redistribution")  ///
			coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th") ///
			title("full sample", size(small)) ///
			name(ML3_marg1, replace) 
			
		* Predicted values		
		estimates restore ML3
		sum Gini_disp_pm if e(sample), detail 
		
		margins, at(income_equi_quint=(1/5) Gini_disp_pm=(.393)) post
			eststo ML3_high

		estimates restore ML3	
		margins, at(income_equi_quint=(1/5) Gini_disp_pm=(.245)) post
			eststo ML3_low

			coefplot ///
				(ML3_high, msymbol(+) mcolor(orange_red) level(95 85) ciopts(color(orange_red orange_red))) ///
				(ML3_low, msymbol(+) mcolor(dknavy) level(95 85) ciopts(color(dknavy dknavy))), ///		
				legend(off) ///
				xtitle("income quintile") title(" ") ytitle("support for redistribution") ///
				vertical ///
				ylabel(2 (.2) 3.2) ///
				coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th") ///
				text(3.15 3 "high inequality", color(orange_red) size(small)) ///
				text(2.3 3 "low inequality", color(dknavy) size(small)) ///
				title("full sample", size(small)) ///
				name(ML3_marg2, replace) 					
		
		
		*** Model 6
		estimates restore ML6

		* Conditional effect plot	
		margins, dydx(Gini_disp_pm) at(income_equi_quint=(1/5)) post
			eststo ML6_marg

		coefplot ///
			(ML6_marg, msymbol(+) mcolor(black) level(95 85) ciopts(color(black black))), ///
			ylabel(0 (1) 5, gmin gmax) vertical ///
			xtitle("income quintile") ytitle("support for redistribution") ///
			coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th") ///
			title("liberal democracies", size(small)) ///
			name(ML6_marg1, replace) 
			
		* Predicted values		
		estimates restore ML6
		sum Gini_disp_pm if e(sample), detail 
		
		margins, at(income_equi_quint=(1/5) Gini_disp_pm=(.372)) post
			eststo ML6_high

		estimates restore ML6	
		margins, at(income_equi_quint=(1/5) Gini_disp_pm=(.245)) post
			eststo ML6_low

			coefplot ///
				(ML6_high, msymbol(+) mcolor(orange_red) level(95 85) ciopts(color(orange_red orange_red))) ///
				(ML6_low, msymbol(+) mcolor(dknavy) level(95 85) ciopts(color(dknavy dknavy))), ///		
				legend(off) ///
				xtitle("income quintile") title(" ") ytitle("support for redistribution") ///
				vertical ///
				ylabel(2 (.2) 3.2) ///
				coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th") ///
				text(3.15 3 "high inequality", color(orange_red) size(small)) ///
				text(2.3 3 "low inequality", color(dknavy) size(small)) ///
				title("liberal democracies", size(small)) ///
				name(ML6_marg2, replace) 						
				
		* combine
		graph combine ML3_marg1 ML6_marg1, title("conditional effect", size(small)) imargin(tiny) name(condeff, replace)
		
		graph combine ML3_marg2 ML6_marg2, title("predicted values", size(small)) imargin(tiny) name(predval, replace)
		
		graph combine condeff predval, row(2) imargin(tiny) iscale(*1.8) ysize(5) name(Figure2, replace)	
		
		graph export "Figure2.pdf", replace
		graph export "Figure2.jpg", width(5000) replace

		
		
**# Bookmark #9	
********************************************************************************		
********* Robustness: Multilevel models with income deciles ********************
********************************************************************************			
	clear
	use "Combined_individual.dta"
	
	
	* count valid observations with redistribution attitude
	gen redistr_valid=1 if redistribution!=.
	bysort country: fre year if year_ISSPwave<.
	
	gen countryonlyonce=1 if country == "UA" | country == "TR" | country == "TH" | country == "SR" | country == "NL" | country == "KR" | country == "EE" | country == "CN" | country == "BE" | country == "AR"
	drop if countryonlyonce==1
	
	* Check which country-years may be problematic
	drop if year_ISSPwave==.
	bysort CountryYear: tab income_equi_dec
	gen omit=1 if CountryYear=="IL1999" | CountryYear=="IT1987" 
	

	
gen income_equi_quint2=income_equi_quint
replace income_equi_quint2=6 if income_equi_dec==10
	
	****
	* M3: random slope model with cross-level interaction with income and with education (posterior mean)
	mixed redistribution c.Gini_disp_pm##i.income_equi_dec c.Gini_disp_pm##i.education c.yeartrend##c.yeartrend i.male i.age_intervals i.country_id || CountryYear: i.income_equi_dec i.education, stddeviations 
		estat ic
		eststo ML3_dec

	* M6: random slope model with cross-level interaction with income and with education (posterior mean)
	mixed redistribution c.Gini_disp_pm##i.income_equi_dec c.Gini_disp_pm##i.education c.yeartrend##c.yeartrend i.male i.age_intervals i.country_id if v2x_regime==3 & omit!=1 || CountryYear: i.income_equi_dec i.education, stddeviations 
		estat ic
		eststo ML6_dec

	* Regression Table		
	esttab ML3_dec ML6_dec ///
		using "MLTable_dec.rtf", b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps compress ///
		replace ///
		label scalars(r2) transform(ln*: exp(@) exp(@))		
		
	
		
	***** Plots	
		*** Model 3
		estimates restore ML3_dec
		
		* Conditional effect plot	
		margins, dydx(Gini_disp_pm) at(income_equi_dec=(1/10)) post
			eststo ML3_marg

		coefplot ///
			(ML3_marg, msymbol(+) mcolor(black) level(95 85) ciopts(color(black black))), ///
			ylabel(0 (1) 5, gmin gmax) vertical ///
			xtitle("income quintile") ytitle("support for redistribution")  ///
			coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th" 6._at="6th" 7._at="7th" 8._at="8th" 9._at="9th" 10._at="10th") ///
			title("full sample", size(small)) ///
			name(ML3_marg1, replace) 
			
		* Predicted values		
		estimates restore ML3_dec
		sum Gini_disp_pm if e(sample), detail 
		
		margins, at(income_equi_dec=(1/10) Gini_disp_pm=(.393)) post
			eststo ML3_high

		estimates restore ML3_dec	
		margins, at(income_equi_dec=(1/10) Gini_disp_pm=(.245)) post
			eststo ML3_low

			coefplot ///
				(ML3_high, msymbol(+) mcolor(orange_red) level(95 85) ciopts(color(orange_red orange_red))) ///
				(ML3_low, msymbol(+) mcolor(dknavy) level(95 85) ciopts(color(dknavy dknavy))), ///		
				legend(off) ///
				xtitle("income quintile") title(" ") ytitle("support for redistribution") ///
				vertical ///
				ylabel(2 (.2) 3.2) ///
				coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th" 6._at="6th" 7._at="7th" 8._at="8th" 9._at="9th" 10._at="10th") ///
				text(3.25 5.5 "high inequality", color(orange_red) size(small)) ///
				text(2.25 5.5 "low inequality", color(dknavy) size(small)) ///
				title("full sample", size(small)) ///
				name(ML3_marg2, replace) 					
		
		
		*** Model 6
		estimates restore ML6_dec

		* Conditional effect plot	
		margins, dydx(Gini_disp_pm) at(income_equi_dec=(1/10)) post
			eststo ML6_marg

		coefplot ///
			(ML6_marg, msymbol(+) mcolor(black) level(95 85) ciopts(color(black black))), ///
			ylabel(0 (1) 5, gmin gmax) vertical ///
			xtitle("income quintile") ytitle("support for redistribution") ///
			coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th" 6._at="6th" 7._at="7th" 8._at="8th" 9._at="9th" 10._at="10th") ///
			title("liberal democracies", size(small)) ///
			name(ML6_marg1, replace) 
			
		* Predicted values		
		estimates restore ML6_dec
		sum Gini_disp_pm if e(sample), detail 
		
		margins, at(income_equi_dec=(1/10) Gini_disp_pm=(.372)) post
			eststo ML6_high

		estimates restore ML6_dec	
		margins, at(income_equi_dec=(1/10) Gini_disp_pm=(.245)) post
			eststo ML6_low

			coefplot ///
				(ML6_high, msymbol(+) mcolor(orange_red) level(95 85) ciopts(color(orange_red orange_red))) ///
				(ML6_low, msymbol(+) mcolor(dknavy) level(95 85) ciopts(color(dknavy dknavy))), ///		
				legend(off) ///
				xtitle("income quintile") title(" ") ytitle("support for redistribution") ///
				vertical ///
				ylabel(2 (.2) 3.2) ///
				coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th" 6._at="6th" 7._at="7th" 8._at="8th" 9._at="9th" 10._at="10th") ///
				text(3.25 5.5 "high inequality", color(orange_red) size(small)) ///
				text(2.25 5.5 "low inequality", color(dknavy) size(small)) ///
				title("liberal democracies", size(small)) ///
				name(ML6_marg2, replace) 						
				
		* combine
		graph combine ML3_marg1 ML6_marg1, title("conditional effect", size(small)) imargin(tiny) ycommon name(condeff, replace)
		
		graph combine ML3_marg2 ML6_marg2, title("predicted values", size(small)) imargin(tiny) ycommon name(predval, replace)
		
		graph combine condeff predval, row(2) imargin(tiny) iscale(*1.7) ysize(5) name(FigureE1, replace)	
		
		graph export "FigureE1.pdf", replace
			
	
	
	
**# Bookmark #10	
********************************************************************************		
********** Alternative outcome variable: redistribution index ******************
********************************************************************************			
	clear
	use "Combined_individual.dta"	
	
	* Table F1: Factor analysis of redistribution items
	factor redistribution tax_richvspoor incdiffstoolarge, pcf
		

*** Scatterplots: Changes: Mean support for redistribution and Gini index of disposable income
	use "Combined_collapsed.dta"
	
		* Table F2: Pairwise correlations between aggregate level changes
		pwcorr redistribution_index_change redist_change tax_change incdiffstoolarge_change Gini_disp_pm_change if !missing(redistribution_index_change) & !missing(Gini_disp_pm_change), obs sig 	
		pwcorr redistribution_index_change redist_change tax_change incdiffstoolarge_change Gini_disp_pm_change if !missing(redistribution_index_change) & !missing(Gini_disp_pm_change) 	

		pwcorr redistribution_index_change Gini_disp_pm_change, obs sig 
		
		
		* Figure F1: Changes in income inequality vs. changes in support for redistribution (index)
		twoway (lfit redistribution_index_change Gini_disp_pm_change , text(-.375 0.055 "r=0.35, p=0.004 (n=68)", size(small))) ///
			(rspike  Gini_disp_pm_change_ub_SE Gini_disp_pm_change_lb_SE redistribution_index_change, horizontal lstyle(ci) lcolor(orange_red%20)) ///
			(scatter redistribution_index_change Gini_disp_pm_change, ///
			mcolor(orange_red) msymbol(dh) yline(0) xline(0)  ///
			xscale(range(-.04 .08)) xlabel(-.1 (.02) .1) ylabel(-.4 (.2) .6, gmin gmax)) ///
			(scatter redistribution_index_change Gini_disp_pm_change if (abs(Gini_disp_pm_change)>.028 | redistribution_index_change>0.3 | redistribution_index_change<-0.3), ///
			mcolor(orange_red) msymbol(dh) mlabel(CountryYear) mlabsize(vsmall) mlabcolor(gs10) mlabpos(12) yline(0) xline(0)  ///
			xscale(range(-.04 .08)) xlabel(-.1 (.02) .1) ylabel(-.4 (.2) .6, gmin gmax)), ///
			legend(off) ///
			ytitle("Change in redistribution support (index)", size(small)) ///
			xtitle("Change in disposable income Gini", size(small)) ///
			title(" ", size(small)) ///
			scale(*1.3) ///
			name(FigureF1, replace)		
			
			graph export "FigureF1.pdf", replace		

	
*** Aggregate-level regressions
	
	***** Redistribution index

		*** All countries
		* Plus trend
		mi estimate, post: reg redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend, cluster(country)
		eststo m1
		
			mibeta redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m2
		
			mibeta redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)		

		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redistribution_index_change Gini_disp_change redistribution_index_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)
		eststo m3
		
			mibeta redistribution_index_change Gini_disp_change redistribution_index_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop, cluster(country)		
	
			
		*** Liberal democracies only
		* Plus trend
		mi estimate, post: reg redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m4
		
			mibeta redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend if v2x_regime>2 & v2x_regime<.
			
		* Plus substantive controls
		mi estimate, post: reg redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m5
		
			mibeta redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)

		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redistribution_index_change Gini_disp_change redistribution_index_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)
		eststo m6
		
			mibeta redistribution_index_change Gini_disp_change redistribution_index_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if v2x_regime>2 & v2x_regime<., cluster(country)	
			
		*** Advanced democracies only
		* Plus trend
		mi estimate, post: reg redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend if estdem==1, cluster(country)
		eststo m7
		
			mibeta redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend if estdem==1, cluster(country)
			
		* Plus substantive controls
		mi estimate, post: reg redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m8	
		
			mibeta redistribution_index_change Gini_disp_change c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		
		* Plus substantive controls and lagged redistribution support
		mi estimate, post: reg redistribution_index_change Gini_disp_change redistribution_index_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		eststo m9		
		
			mibeta redistribution_index_change Gini_disp_change redistribution_index_lag c.yeartrend##c.yeartrend gdp_capita_con_growth netmigr_cum_bypop if estdem==1, cluster(country)
		
		// de facto included: 
			// Austria, Australia, Canada, Denmark, Germany
			// Finland, France, Israel, Italy, Japan
			// Norway, New Zealand, Portugal, Sweden
			// Spain, UK, USA	
					
		*** Regression Table
			esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 using "TableF3.rtf" ///
				, b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps nomtitles compress ///
				scalars(r2) replace 			


				
				
****************************** Multilevel models *******************************
	clear
	use "Combined_individual.dta"
	
	
	* count valid observations with redistribution attitude
	gen redistribution_index_valid=1 if redistribution_index!=.
	bysort country: fre year if year_ISSPwave<. & redistribution_index_valid==1
	
	gen countryonlyonce=1 if country == "UA" | country == "TR" | country == "TH" | country == "SR" | country == "NL" | country == "KR" | country == "EE" | country == "CN" | country == "BE" | country == "AR"
	drop if countryonlyonce==1
	
	
	***** Estimate ML models
	*** All countries
	* M1: random intercept model (multiple imputation)
	mi estimate, post dots: mixed redistribution_index Gini_disp c.yeartrend##c.yeartrend i.income_equi_quint i.male i.age_intervals i.education i.country_id  || CountryYear:, stddeviations
		eststo ML1_index
		estimates save ML1_index, replace
		
	* M2: random intercept model (posterior mean)
	mixed redistribution_index Gini_disp_pm c.yeartrend##c.yeartrend i.income_equi_quint i.male i.age_intervals i.education i.country_id  || CountryYear:, stddeviations
		estat ic
		eststo ML2_index

	* M3: random slope model with cross-level interaction with income and with education (posterior mean)
	mixed redistribution_index c.Gini_disp_pm##i.income_equi_quint c.Gini_disp_pm##i.education c.yeartrend##c.yeartrend i.male i.age_intervals i.country_id || CountryYear: i.income_equi_quint i.education, stddeviations
		estat ic
		eststo ML3_index
		
		
	*** Liberal democracies only
	* M4: random intercept model (multiple imputation)
	mi estimate, post dots: mixed redistribution_index Gini_disp c.yeartrend##c.yeartrend i.income_equi_quint i.male i.age_intervals i.education i.country_id if v2x_regime>2 & v2x_regime<. || CountryYear:, stddeviations
		eststo ML4_index
		estimates save ML4_index, replace
			
	* M5: random intercept model (posterior mean)
	mixed redistribution_index Gini_disp_pm c.yeartrend##c.yeartrend i.income_equi_quint i.male i.age_intervals i.education i.country_id if v2x_regime>2 & v2x_regime<. || CountryYear:, stddeviations
		estat ic
		eststo ML5_index

	* M6: random slope model with cross-level interaction with income and with education (posterior mean)
	mixed redistribution_index c.Gini_disp_pm##i.income_equi_quint c.Gini_disp_pm##i.education c.yeartrend##c.yeartrend i.male i.age_intervals i.country_id if v2x_regime>2 & v2x_regime<. || CountryYear: i.income_equi_quint i.education, stddeviations
		estat ic
		eststo ML6_index

	* Regression Table F4: Linear multilevel models of support for redistribution (index)
	esttab ML1_index ML2_index ML3_index ML4_index ML5_index ML6_index ///
		using "TableF4.rtf", b(a2) se(a2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps compress ///
		replace ///
		label scalars(r2) transform(ln*: exp(@) exp(@))		
		
		
		
	***** Figure F2: Inequality, income quintile and support for redistribution (index)
		*** Model 3
		estimates restore ML3_index
		
		* Conditional effect plot	
		margins, dydx(Gini_disp_pm) at(income_equi_quint=(1/5)) post
			eststo ML3_marg

		coefplot ///
			(ML3_marg, msymbol(+) mcolor(black) level(95 85) ciopts(color(black black))), ///
			ylabel(0 (1) 4, gmin gmax) vertical ///
			xtitle("income quintile") ytitle("support for redistribution")  ///
			coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th") ///
			title("full sample", size(small)) ///
			name(ML3_marg1, replace) 
			
		* Predicted values		
		estimates restore ML3_index
		sum Gini_disp_pm if e(sample), detail 
		
		margins, at(income_equi_quint=(1/5) Gini_disp_pm=(.393)) post
			eststo ML3_high

		estimates restore ML3_index	
		margins, at(income_equi_quint=(1/5) Gini_disp_pm=(.245)) post
			eststo ML3_low

			coefplot ///
				(ML3_high, msymbol(+) mcolor(orange_red) level(95 85) ciopts(color(orange_red orange_red))) ///
				(ML3_low, msymbol(+) mcolor(dknavy) level(95 85) ciopts(color(dknavy dknavy))), ///		
				legend(off) ///
				xtitle("income quintile") title(" ") ytitle("support for redistribution") ///
				vertical ///
				ylabel(2.4 (.2) 3.4, gmin gmax) ///
				coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th") ///
				text(3.3 3 "high inequality", color(orange_red) size(small)) ///
				text(2.6 3 "low inequality", color(dknavy) size(small)) ///
				title("full sample", size(small)) ///
				name(ML3_marg2, replace) 					
		
		
		*** Model 6
		estimates restore ML6_index

		* Conditional effect plot	
		margins, dydx(Gini_disp_pm) at(income_equi_quint=(1/5)) post
			eststo ML6_marg

		coefplot ///
			(ML6_marg, msymbol(+) mcolor(black) level(95 85) ciopts(color(black black))), ///
			ylabel(0 (1) 4, gmin gmax) vertical ///
			xtitle("income quintile") ytitle("support for redistribution") ///
			coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th") ///
			title("liberal democracies", size(small)) ///
			name(ML6_marg1, replace) 
			
		* Predicted values		
		estimates restore ML6_index
		sum Gini_disp_pm if e(sample), detail 
		
		margins, at(income_equi_quint=(1/5) Gini_disp_pm=(.372)) post
			eststo ML6_high

		estimates restore ML6_index	
		margins, at(income_equi_quint=(1/5) Gini_disp_pm=(.245)) post
			eststo ML6_low

			coefplot ///
				(ML6_high, msymbol(+) mcolor(orange_red) level(95 85) ciopts(color(orange_red orange_red))) ///
				(ML6_low, msymbol(+) mcolor(dknavy) level(95 85) ciopts(color(dknavy dknavy))), ///		
				legend(off) ///
				xtitle("income quintile") title(" ") ytitle("support for redistribution") ///
				vertical ///
				ylabel(2.4 (.2) 3.4, gmin gmax) ///
				coeflabel(1._at="1st" 2._at="2nd" 3._at="3rd" 4._at="4th" 5._at="5th") ///
				text(3.3 3 "high inequality", color(orange_red) size(small)) ///
				text(2.6 3 "low inequality", color(dknavy) size(small)) ///
				title("liberal democracies", size(small)) ///
				name(ML6_marg2, replace) 						
				
		* combine
		graph combine ML3_marg1 ML6_marg1, title("conditional effect", size(small)) imargin(tiny) name(condeff, replace)
		
		graph combine ML3_marg2 ML6_marg2, title("predicted values", size(small)) imargin(tiny) name(predval, replace)
		
		graph combine condeff predval, row(2) imargin(tiny) iscale(*1.6) ysize(5) name(FigureF2, replace)	
		
		graph export "FigureF2.pdf", replace

		
log close
